/**
 * Generator函数执行器
 * @param generator	Generator函数
 */
export default function runGenerator(generator:GeneratorFunction):Promise<any>{
	return new Promise((resolve) => {
		const iterator=generator();
		function inner({value,done}:IteratorResult<unknown>):any{
			if(done){
				return value;
			}
			return Promise.resolve(value).then(function(result){
				return inner(iterator.next(result));
			},function(error){
				return inner(iterator.throw(error));
			});
		}
		resolve(inner(iterator.next()));
	});
}